package com.learn.demo.async;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 测试异步执行
 *
 * @author banjiawei
 * @date 2021/12/27
 */
@RestController
@RequestMapping("/testAsync")
public class TestAsyncController {

    @Autowired
    private TestAsyncService testAsyncService;

    @GetMapping("/testService")
    public void testService(){
        try {
            testAsyncService.service1();
            testAsyncService.service2();
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    @GetMapping("/testAsyncService")
    public void testAsyncService(){
        try {
            testAsyncService.asyncService1();
            testAsyncService.asyncService2();
        }catch (Exception e){
            e.printStackTrace();
        }
    }

    @GetMapping("/testAsyncReturnService")
    public String testAsyncReturnService(){
        try {
            testAsyncService.asyncService4();
            return "OK";
        }catch (Exception e){
            e.printStackTrace();
        }
        return "No";
    }
}
